import React, {Component} from 'react';
import {connect} from 'dva';
import {routerRedux} from 'dva/router';
import { Picker, List } from 'antd-mobile';
import {createForm} from 'rc-form';
import convertValue from './convertEducation';

class PickerComponent extends Component {

  constructor(props) {
    super(props);
    this.state = {
      value:[]
    }
  }

  componentDidMount(){
    const { displayDefaults } = this.props;
    const v = convertValue.stringToNum(displayDefaults)
    console.log('displayDefaults',displayDefaults);
    this.setState({
      value: v,
    })
  }

  componentWillReceiveProps(newProps){
    const v = convertValue.stringToNum(newProps.displayDefaults)
    this.setState({
      value: v,
    })
  }

  pickerClick = (v) =>{
    this.setState({
      value:v
    })
    this.props.onSave(v)
  }


  render() {

    const { value } = this.state;
    const {data, title, displayNull, displayDefaults, header} = this.props;

      console.log('value',value);
    return (
        <Picker
          data={data}
          title={title}
          cascade={false}
          extra={displayNull}
          value={value}
          onChange={(v) => this.pickerClick(v)}
          >
          <List.Item arrow="horizontal">{header}</List.Item>
        </Picker>
    );
  }

}

const PickerComponentWrapper = createForm()(PickerComponent);

export default connect()(PickerComponentWrapper);
